package com.wandian.cqcsk.mvvm.mine;

import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.bumptech.glide.Glide;
import com.bytedance.sdk.openadsdk.TTAdConstant;
import com.bytedance.sdk.openadsdk.TTAdNative;
import com.bytedance.sdk.openadsdk.TTRewardVideoAd;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.mylib.libcore.AppContext;
import com.mylib.libcore.bean.EveryDayCoin;
import com.mylib.libcore.bean.EveryDayConfigBean;
import com.mylib.libcore.bean.UserInfoBean;
import com.mylib.libcore.config.AppConfig;
import com.mylib.libcore.config.CoinTypeEnum;
import com.mylib.libcore.config.RouterConfig;
import com.mylib.libcore.eventbus.ChangeMessage;
import com.mylib.libcore.mvvm.BaseMVVMFragment;
import com.mylib.libcore.tools.CSJADTools;
import com.mylib.libcore.tools.TTAdManagerHolder;
import com.mylib.libcore.utils.ActivityUtil;
import com.mylib.libcore.utils.GlideUtil;
import com.mylib.libcore.utils.ToastUtil;
import com.mylib.libcore.utils.UIUtils;
import com.mylib.widget.CustomCoinToast;
import com.mylib.widget.CustomItemCoinView;
import com.wandian.cqcsk.R;
import com.wandian.cqcsk.adapter.mine.MineRecycleAdapter;
import com.wandian.cqcsk.bean.MineServiceItem;
import com.wandian.cqcsk.databinding.FragmentMineBinding;
import com.wandian.cqcsk.dialog.HomeEWMDialog;
import com.wandian.cqcsk.dialog.MineKFDialog;
import com.wandian.cqcsk.dialog.SignInDialogWindow;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import static com.mylib.libcore.config.AppSPKeyConfig.APP_MINE_COIN_SET;

/**
 * @author Administrator
 * @date 2019/12/16-13:30
 * @description 我的
 **/
@Route(path = RouterConfig.ROUTER_HOME_FRAGMENT_MINE)
public class FragmentMine extends BaseMVVMFragment<FragmentMineViewModel> implements SignInDialogWindow.SignInDialogClink  {

    private FragmentMineBinding dataBinding;
    private MineRecycleAdapter mineRecycleAdapter;
    private SignInDialogWindow signInDialogWindow;//签到弹框
    private HomeEWMDialog homeEWMDialog;//二维码弹框
    private UserInfoBean userInfoBean; //用户信息
    private EveryDayConfigBean everyDayConfigBean; //用户每日配置
    private String function_tabs =""; //开放功能
    private int lottery_num = 0; //抽奖次数
    private EveryDayCoin everyDayCoin;//每日金币
    private MineKFDialog kfDialog;//客服弹框
    private List<CustomItemCoinView> listCoinView = new ArrayList<>();
    //看视频
    private TTRewardVideoAd mRewardVideoAd;
    private TTAdNative mTTAdNative;
    private boolean videoPrepare = false;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

    @Override
    public View initView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        dataBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_mine, container, false);
        return dataBinding.getRoot();
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        if(!UIUtils.isEmpty(dataBinding)) EventBus.getDefault().register(this);
        UIUtils.setKeyEveryDayCoin(CoinTypeEnum.LOGIN_COIN);
        function_tabs = AppContext.getInstance().getAppPreferenceForever().getMainTabs()+"";
        userInfoBean = AppContext.getInstance().getAppPreferencesHelper().getUserInfoBean();
        everyDayConfigBean = AppContext.getInstance().getAppPreferencesHelper().getEveryDayConfig();
        everyDayCoin = AppContext.getInstance().getAppPreferenceForever().getEveryDayCoin();
        getEveryDayCoinData();
        initRecycle();
        initClink();
        initViewData();
        getData();
        initCSJAD();
        listCoinView.clear();
        listCoinView.add(dataBinding.bindCoin.cusCoin1);
        listCoinView.add(dataBinding.bindCoin.cusCoin2);
        listCoinView.add(dataBinding.bindCoin.cusCoin3);
        listCoinView.add(dataBinding.bindCoin.cusCoin4);
        listCoinView.add(dataBinding.bindCoin.cusCoin5);
        listCoinView.add(dataBinding.bindCoin.cusCoin6);
        listCoinView.add(dataBinding.bindCoin.cusCoin7);
        listCoinView.add(dataBinding.bindCoin.cusCoin8);
        listCoinView.add(dataBinding.bindCoin.cusCoin9);
        listCoinView.add(dataBinding.bindCoin.cusCoin10);
        listCoinView.add(dataBinding.bindCoin.cusCoin11);
        listCoinView.add(dataBinding.bindCoin.cusCoin12);
        listCoinView.add(dataBinding.bindCoin.cusCoin13);
        listCoinView.add(dataBinding.bindCoin.cusCoin14);
    }

    @Override
    public void onResume() {
        super.onResume();
        if(!UIUtils.isFastRequest()){
            getData();
            initViewData();
        }
    }

    private void getData(){
        mViewModel.getUserInfo(); //获取用户信息
        mViewModel.getConfigInfo();   //获取每日配置
    }

    //初始化穿山甲广告
    private void initCSJAD( ){
        try{
            TTAdManagerHolder.init(getContext());
            mTTAdNative = TTAdManagerHolder.getTTAdNative(getContext());
            mTTAdNative.loadRewardVideoAd(CSJADTools.getAdSlot("签到奖励",3,"sign"),
                    new TTAdNative.RewardVideoAdListener() {
                        @Override
                        public void onError(int i, String s) {
                            videoPrepare = false;
                        }

                        @Override
                        public void onRewardVideoAdLoad(TTRewardVideoAd ttRewardVideoAd) {
                            videoPrepare = false;
                            if(UIUtils.isEmpty(ttRewardVideoAd)) return;
                            mRewardVideoAd = ttRewardVideoAd;
                        }
                        @Override
                        public void onRewardVideoCached() {
                            videoPrepare = true;
                        }
                    });

        }catch (Exception e){}
    }

    //准备视频
    private void prepareVideo(){
        if (mRewardVideoAd != null && videoPrepare) {
            mRewardVideoAd.setRewardAdInteractionListener(new TTRewardVideoAd.RewardAdInteractionListener() {
                @Override
                public void onAdShow() { }

                @Override
                public void onAdVideoBarClick() { }

                @Override
                public void onAdClose() {
                    CustomCoinToast.showToast(getContext(),"签到额外奖励","3金币");
                }

                @Override
                public void onVideoComplete() {}

                @Override
                public void onVideoError() {}

                @Override
                public void onRewardVerify(boolean b, int i, String s, int i1, String s1) { }

                @Override
                public void onSkippedVideo() { }
            });
            //展示广告，并传入广告展示的场景
            mRewardVideoAd.showRewardVideoAd(getActivity(), TTAdConstant.RitScenes.CUSTOMIZE_SCENES, "scenes_test");
        } else{
            ToastUtil.show("视频资源准备中，请稍后再试");
            initCSJAD();
        }
    }

    private void initViewData(){
        dataBinding.bindInvite.ivIcon.setBackgroundResource(R.drawable.img_mine_my_invite);
        dataBinding.bindInvite.tvLeft.setText("推荐人ID");
        dataBinding.bindInvite.tvRight.setText("去填写");
        dataBinding.bindInvite.tvRight.setTextColor(getContext().getResources().getColor(R.color.gray));

        dataBinding.bindHelp.ivIcon.setBackgroundResource(R.drawable.img_mine_help);
        dataBinding.bindHelp.tvLeft.setText("帮助与反馈");
        dataBinding.bindSetting.ivIcon.setBackgroundResource(R.drawable.img_mine_setting);
        dataBinding.bindSetting.tvLeft.setText("设置");

        //是否显示新闻设置
        if(function_tabs.contains("资讯")) dataBinding.bindNewsSet.rlNextPage.setVisibility(View.VISIBLE);
        else dataBinding.bindNewsSet.rlNextPage.setVisibility(View.GONE);
        dataBinding.bindNewsSet.tvLeft.setText("资讯设置");
        dataBinding.bindNewsSet.ivIcon.setBackgroundResource(R.drawable.img_news_set_icon);
        dataBinding.bindHomeBtnSet.tvLeft.setText("主页设置");
        dataBinding.bindHomeBtnSet.ivIcon.setBackgroundResource(R.drawable.img_home_set_icon);

        dataBinding.bindItemIvRightBtn.ivIcon.setBackgroundResource(R.drawable.img_mine_coin_set);
        dataBinding.bindItemIvRightBtn.tvLeft.setText("金币设置");
        String coinState = AppContext.getInstance().getAppPreferenceForever().getKeyValue(APP_MINE_COIN_SET);
        if(!UIUtils.isEmpty(coinState) && coinState.equals("0")){
            dataBinding.bindItemIvRightBtn.ivBtn.setImageResource(R.drawable.toggle_off);
        }else dataBinding.bindItemIvRightBtn.ivBtn.setImageResource(R.drawable.toggle_on);

        //刷新用户信息
        mViewModel.userBean.observe(this,userBean->{
            if(!UIUtils.isEmpty(userBean)){
                this.userInfoBean = userBean;
                if(!UIUtils.isEmpty(userBean.getOnlineTime()) && userBean.getOnlineTime()>0){
                    dataBinding.tvActiveTime.setText(UIUtils.doubleSavePointNumber((double) userBean.getOnlineTime()/60,2)+"小时");
                }else dataBinding.tvActiveTime.setText("0.01小时");
                notifyMineUI();
            }else  dataBinding.tvActiveTime.setText("0.01小时");
        });

        mViewModel.signState.observe(this,signState->{
            if(!UIUtils.isEmpty(signState) && signState.equals("1")){
                ToastUtil.show("签到奖励1金币");
                if(signInDialogWindow != null)signInDialogWindow.notifyTodaySignData();
            }
        });

        //获取每日配置信息
        mViewModel.everyDayConfig.observe(this,everyDayConfig->{
            if(!UIUtils.isEmpty(everyDayConfig)){
                this.everyDayConfigBean = everyDayConfig;
                if(!UIUtils.isEmpty(everyDayConfigBean.getSignTag()) && everyDayConfigBean.getSignTag()==0){
                    dataBinding.cusSign.showIvState();
                    AppContext.getInstance().getAppPreferencesHelper().setKeyValue("rank_id_"+userInfoBean.getId(),"");
                    UIUtils.clearEveryDayCoin();
                }else dataBinding.cusSign.hideIvState();
                if(!UIUtils.isEmpty(everyDayConfigBean.getClockTag()) && everyDayConfigBean.getClockTag()==0){
                    dataBinding.cusDk.showIvState();
                }else dataBinding.cusDk.hideIvState();
            }
        });
        //刷新ui页面
        notifyMineUI();
    }

    //刷新ui页面
    private void notifyMineUI(){
        //推荐人
        if(!UIUtils.isEmpty(userInfoBean.getpUserId()) && !userInfoBean.getpUserId().equals("0")){
            dataBinding.bindInvite.ivNextPage.setVisibility(View.GONE);
            dataBinding.bindInvite.tvRight.setTextColor(getContext().getResources().getColor(R.color.colorthree));
            dataBinding.bindInvite.tvRight.setText(userInfoBean.getpUserId()+"");
        }
        //在线时长-抽奖
        dataBinding.ivLettory.setVisibility(View.GONE);
        if(function_tabs.contains("广告")){
            int lotteryNum = everyDayConfigBean.getLotteryNum();
            if(!UIUtils.isEmpty(lotteryNum) && lotteryNum<=10){//限制每天10,配置错误不显示
                if(!UIUtils.isEmpty(userInfoBean) && !UIUtils.isEmpty(userInfoBean.getIntraDayTime()) && lotteryNum>0 && userInfoBean.getIntraDayTime()>=6){
                    if((10-lotteryNum)*6<=userInfoBean.getIntraDayTime()-6){}
                    dataBinding.ivLettory.setVisibility(View.VISIBLE);
                    UIUtils.setKeyEveryDayCoin(CoinTypeEnum.LL_COIN);
                    UIUtils.setKeyEveryDayCoin(CoinTypeEnum.ON_LINE_COIN);
                    lottery_num = 10+userInfoBean.getIntraDayTime()/6-lotteryNum;
                }
            }
        }

        dataBinding.tvUserName.setText(userInfoBean.getNickName()+"");//昵称
        dataBinding.tvUserActive.setText(userInfoBean.getOtLv()+"");//活跃度
        dataBinding.tvUserLevel.setText("LV-"+userInfoBean.getExLv()+"级");//等级
        dataBinding.tvUserDes.setText(userInfoBean.getDescription()+"");//描述
        if(!UIUtils.isEmpty(userInfoBean.getHeadPic()))GlideUtil.loadhead(getContext(),userInfoBean.getHeadPic(),dataBinding.ivHead);
        dataBinding.tvNotepadNumber.setText(userInfoBean.getMemoNum()+""); //备忘数
        dataBinding.tvCoinNumber.setText(userInfoBean.getGoldNum()+"");//金币
        dataBinding.tvZlNumber.setText(userInfoBean.getFightNum()+"");//战力
        dataBinding.tvGkNumber.setText(userInfoBean.getEmigratedNum()+"");//关卡
    }

    private void initRecycle(){
        RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getContext(),4);
        dataBinding.recycler.setLayoutManager(layoutManager);
        mineRecycleAdapter  = new MineRecycleAdapter(R.layout.item_mine_grid_one);
        dataBinding.recycler.setAdapter(mineRecycleAdapter);
        List<MineServiceItem> itemBeans = new ArrayList<>();
        itemBeans.add(new MineServiceItem("我的钱包",R.drawable.img_mine_qb));
        itemBeans.add(new MineServiceItem("邀请有奖",R.drawable.img_mine_yqyj));
        itemBeans.add(new MineServiceItem("排名奖励",R.drawable.img_mine_rank_icon));
        itemBeans.add(new MineServiceItem("战力挑战",R.drawable.img_mine_fight));
        if(UIUtils.isOpenAD()){
            itemBeans.add(new MineServiceItem("休闲一会",R.drawable.img_home_btn_games_unselect));
            itemBeans.add(new MineServiceItem("小说天地",R.drawable.img_home_btn_book_unselect));
            itemBeans.add(new MineServiceItem("微文精选",R.drawable.img_home_btn_wxtop_unselect));
            itemBeans.add(new MineServiceItem("闯关问答",R.drawable.img_mine_cg_icon));
        }
        itemBeans.add(new MineServiceItem("地图天气",R.drawable.img_mine_map));
        itemBeans.add(new MineServiceItem("每日英语",R.drawable.img_mine_everyday_english));
        itemBeans.add(new MineServiceItem("知识宝库",R.drawable.img_mine_knowledge));
        itemBeans.add(new MineServiceItem("生活百科",R.drawable.img_mine_life));
        mineRecycleAdapter.setNewData(itemBeans);
        //金币
        dataBinding.llCoin.setOnClickListener(v ->  ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_MY_WALLET).navigation());
        //战力
        dataBinding.llZhanli.setOnClickListener(v -> {
            Bundle bundle = new Bundle();
            bundle.putString("zl_num",userInfoBean.getFightNum()+"");
            bundle.putString("zl_times",everyDayConfigBean.getFightNum()+"");
            ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_NEWS_CHALLENGE).with(bundle).navigation();
        });
        //闯关
        dataBinding.llChuanguang.setOnClickListener(v ->{
            Bundle bundle = new Bundle();
            bundle.putString("cg_num",userInfoBean.getEmigratedNum()+"");
            bundle.putString("cg_times",everyDayConfigBean.getEmigratedNum()+"");
            ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_NEWS_PASS_THROUGH).with(bundle).navigation();
        });
        //计事
        dataBinding.llNotepad.setOnClickListener(v ->  ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_NOTEPAD_HOME).navigation());
    }

    //获取每日金币信息
    private void getEveryDayCoinData(){
        String coinState = AppContext.getInstance().getAppPreferenceForever().getKeyValue(APP_MINE_COIN_SET);
        if(!UIUtils.isEmpty(coinState) && coinState.equals("0")){
            dataBinding.bindCoin.rlCoin.setVisibility(View.GONE);
        }else {
            if(UIUtils.isOpenAD()){
                dataBinding.bindCoin.rlCoin.setVisibility(View.VISIBLE);
                if(!UIUtils.isEmpty(everyDayCoin)){
                    try {
                        for(CustomItemCoinView view:listCoinView){
                            view.clearAnimation();
                            view.setVisibility(View.GONE);
                        }
                        ArrayList<CoinTypeEnum> coinTitles = new ArrayList<>();
                        if(everyDayCoin.getLogin_coin()==1)coinTitles.add(CoinTypeEnum.LOGIN_COIN);
                        if(everyDayCoin.getOnline_coin()==1)coinTitles.add(CoinTypeEnum.ON_LINE_COIN);
                        if(everyDayCoin.getDk_coin()==1)coinTitles.add(CoinTypeEnum.DK_COIN);
                        if(everyDayCoin.getSign_coin()==1)coinTitles.add(CoinTypeEnum.SIGN_COIN);
                        if(everyDayCoin.getLl_coin()==1)coinTitles.add(CoinTypeEnum.LL_COIN);
                        if(everyDayCoin.getGame_coin()==1)coinTitles.add(CoinTypeEnum.GAME_COIN);
                        if(everyDayCoin.getNovel_coin()==1)coinTitles.add(CoinTypeEnum.NOVEL_COIN);
                        if(everyDayCoin.getTz_coin()==1)coinTitles.add(CoinTypeEnum.TZ_COIN);
                        if(everyDayCoin.getCg_coin()==1)coinTitles.add(CoinTypeEnum.CG_COIN);
                        if(everyDayCoin.getNews_coin()==1)coinTitles.add(CoinTypeEnum.NEWS_COIN);
                        if(everyDayCoin.getWeather_coin()==1)coinTitles.add(CoinTypeEnum.WEATHER_COIN);
                        if(everyDayCoin.getVideo_coin()==1)coinTitles.add(CoinTypeEnum.VIDEO_COIN);
                        if(everyDayCoin.getBk_coin()==1)coinTitles.add(CoinTypeEnum.BK_COIN);
                        if(everyDayCoin.getInvite_coin()==1)coinTitles.add(CoinTypeEnum.INVITE_COIN);
                        if(everyDayCoin.getZs_coin()==1)coinTitles.add(CoinTypeEnum.ZS_COIN);
                        if(everyDayCoin.getLottery_coin()==1)coinTitles.add(CoinTypeEnum.LOTTERY_COIN);
                        if(everyDayCoin.getWw_coin()==1)coinTitles.add(CoinTypeEnum.WW_COIN);
                        if(everyDayCoin.getRank_coin()==1)coinTitles.add(CoinTypeEnum.RANK_COIN);
                        if(coinTitles.size()>6){
                            int nowLength = coinTitles.size();
                            for(int i=0;i<nowLength-6;i++)coinTitles.remove(1);
                        }
                        List<Integer> randListIndex = new ArrayList<>();
                        List<Integer> selectList = new ArrayList<>();
                        for(int i=0;i<14;i++)randListIndex.add(i);
                        Random random = new Random();
                        for(CoinTypeEnum item:coinTitles){
                            int index = random.nextInt(randListIndex.size());
                            selectList.add(randListIndex.get(index));
                            randListIndex.remove(index);
                        }
                        for(int i=0;i<coinTitles.size();i++)initCustomCoinView(selectList.get(i),coinTitles.get(i),"1");
                    }catch (Exception e){}
                }
            }else {
                dataBinding.bindCoin.rlCoin.setVisibility(View.GONE);
            }
        }
    }

    //初始化每日金币
    private void initCustomCoinView(int index,CoinTypeEnum title,String coin){
        if(index<listCoinView.size() && !UIUtils.isEmpty(listCoinView.get(index))) setItemCoin(listCoinView.get(index),title,coin);
    }

    private void setItemCoin(CustomItemCoinView view, CoinTypeEnum title, String coin){
        view.setVisibility(View.VISIBLE);
        view.initCoinView(title,coin);
        ActivityUtil.getInstance().setCoinViewUpDownAnim(view);
        view.setOnClickListener(v ->sendCoin(v,title,coin));
    }
    private void sendCoin(View view,CoinTypeEnum title,String coin){
        view.clearAnimation();
        view.setVisibility(View.GONE);
        UIUtils.notifyEveryDayCoin(title);
        mViewModel.getTaskCoin(getActivity(),dataBinding.llFragmentMine);
    }

    private void initClink(){

        //金币控制
        dataBinding.bindItemIvRightBtn.ivBtn.setOnClickListener(v -> {
            String coinState = AppContext.getInstance().getAppPreferenceForever().getKeyValue(APP_MINE_COIN_SET);
            if(!UIUtils.isEmpty(coinState) && coinState.equals("0")){
                dataBinding.bindItemIvRightBtn.ivBtn.setImageResource(R.drawable.toggle_on);
                AppContext.getInstance().getAppPreferenceForever().setKeyValue(APP_MINE_COIN_SET,"1");
            }else {
                dataBinding.bindItemIvRightBtn.ivBtn.setImageResource(R.drawable.toggle_off);
                AppContext.getInstance().getAppPreferenceForever().setKeyValue(APP_MINE_COIN_SET,"0");
            }
            getEveryDayCoinData();
        });
        dataBinding.bindItemIvRightBtn.ivBtn.setImageResource(R.drawable.toggle_off);
        //推荐人
        dataBinding.bindInvite.rlNextPage.setOnClickListener(v -> {
          if(!UIUtils.isEmpty(userInfoBean.getpUserId()) || !userInfoBean.getpUserId().equals("0"))
              ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_EDIT_INVITE).navigation();
        });
        //设置首页底部按钮
        dataBinding.bindHomeBtnSet.rlNextPage.setOnClickListener(v -> ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_SET_HOME_BTN).navigation());
        //设置我的栏目
        dataBinding.bindNewsSet.rlNextPage.setOnClickListener(v -> ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_SET_NEWS_TABLE).navigation());
        //设置
        dataBinding.bindSetting.rlNextPage.setOnClickListener(v -> ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_SETTING).navigation());
        //个人中心
        dataBinding.ivHeadBg.setOnClickListener(v -> {
            Bundle bundle = new Bundle();
            bundle.putString("title","动态");
            bundle.putString("user_id",userInfoBean.getId()+"");
            bundle.putString("user_name",userInfoBean.getNickName());
            bundle.putString("user_head",userInfoBean.getHeadPic());
            bundle.putString("form_id",userInfoBean.getId()+"");
            bundle.putString("user_des",userInfoBean.getDescription()+"");
            ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_SETTING_USERHEADINFO).with(bundle).navigation();
        });

       // 头像邀请
        dataBinding.ivHead.setOnClickListener(v ->{
            if(UIUtils.isFastClick())return;
            if(UIUtils.isLogin()) showEWMDialog();
            else ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_LOGIN).navigation();
        });
        //签到
        dataBinding.cusSign.setOnClickListener(v -> {
            if(UIUtils.isFastClick()) return;
            showSignDialog();
        });
        //客服
        dataBinding.cusKf.setOnClickListener(v -> {
            if(UIUtils.isFastClick()) return;
            showKFDialog();
        });
        //消息
        dataBinding.cusMessage.setOnClickListener(v -> {
            if(UIUtils.isFastClick()) return;
            ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_MESSAGE_MANAGER).navigation();
        });
        //打卡
        dataBinding.cusDk.setOnClickListener(v -> {
            if(UIUtils.isFastClick()) return;
            if(!UIUtils.isEmpty(everyDayConfigBean.getClockTag()) && everyDayConfigBean.getClockTag()==1){
                ToastUtil.show("今日已打卡");
                Bundle bundle = new Bundle();
                bundle.putString("title","成长");
                bundle.putString("user_id",userInfoBean.getId()+"");
                bundle.putString("user_name",userInfoBean.getNickName());
                bundle.putString("user_head",userInfoBean.getHeadPic());
                bundle.putString("form_id",userInfoBean.getId()+"");
                bundle.putString("user_des",userInfoBean.getDescription()+"");
                ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_SETTING_USERHEADINFO).with(bundle).navigation();
            }else ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_EVERYDAY_DK).navigation();
        });
        //开启抽奖
        dataBinding.ivLettory.setOnClickListener(v ->  ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_GAMES_LOTTERY).withString("lottery_num",lottery_num+"").navigation());
        Glide.with(this).load(R.drawable.img_mine_task_hb).into(dataBinding.ivLettory);
        //帮助与反馈
       dataBinding.bindHelp.rlNextPage.setOnClickListener(v -> ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_HELPANDSUGGEST).navigation());
    }

    private void showSignDialog(){  //展示签到弹框
        try {
            signInDialogWindow = new SignInDialogWindow(getActivity(),this::signInIvClink);
            signInDialogWindow.showAtLocation(dataBinding.llFragmentMine, Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 0);
        } catch (Exception e) {}
    }

    private void showEWMDialog(){//展示二维码弹框
        try {
            homeEWMDialog = new HomeEWMDialog(getContext(),null);
            homeEWMDialog.showAtLocation(dataBinding.llFragmentMine, Gravity.CENTER, 0, 0);
        } catch (Exception e) {}
    }

    private void showKFDialog(){//客服弹框
        try {
            kfDialog = new MineKFDialog(getContext());
            kfDialog.showAtLocation(dataBinding.llFragmentMine, Gravity.CENTER, 0, 0);
        } catch (Exception e) {}
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void eventBusMessage(ChangeMessage changeMessage) {
        try {
            if(!UIUtils.isEmpty(changeMessage) && !UIUtils.isEmpty(changeMessage.getIsChange()) && changeMessage.getIsChange().equals("changeMine")){
                Log.d("changeMine","changeMine" );
                if(!UIUtils.isFastRequest()){
                    getData();
                    initViewData();
                    everyDayCoin = AppContext.getInstance().getAppPreferenceForever().getEveryDayCoin();
                    getEveryDayCoinData();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onDestroy() {
        try {
            EventBus.getDefault().unregister(this);
        }catch (Exception e){}
        super.onDestroy();
    }

    @Override
    public void signInIvClink() {
        if(UIUtils.isOpenAD())prepareVideo();
        else mViewModel.todaySign(userInfoBean);
    }
}
